package com.github.cyf.async.controller;

import com.github.cyf.async.service.AsyncService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenyifan
 * @create 2024-03-17 16:44
 */
@RestController
@Slf4j
@RequestMapping("/test")
@RequiredArgsConstructor
public class AsyncController {

    private final AsyncService testService;

    /**
     * 正常执行
     * @param msg
     * @return
     */
    @GetMapping("/msg")
    public String sendMessage(String msg) {
        log.info("异步调用发送信息方法");
        testService.sendMessage(msg);
        return "发送成功";
    }

    /**
     * 异常执行
     * @param msg
     * @return
     */
    @GetMapping("/error")
    public String error(String msg) {
        log.info("异步执行错误方法");
        testService.sendError(msg);
        return "发送成功";
    }

}
